﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcMusicStore.Models;

namespace MvcMusicStore.Controllers
{
    
    public class GenreController : Controller
    {
        MusicEntities db = new MusicEntities();

        public ActionResult Index() {

            var grs = db.Genres;
            return View(grs);
        }
        public ActionResult Create()
        {
            
            Genre g = new Genre();
            return View(g);
        }

        [HttpPost]
        public ActionResult CreateAjax()
        {

            Genre g = new Genre() { Description = "Nuevo", Name = "Sarasa" }; 
            return Json(g);
        }

        [HttpPost]
        public ActionResult Create(Genre gr, FormCollection collection)
        {

            if (ModelState.IsValid)
            {
                db.Genres.Add(gr);
                db.SaveChanges();
                return RedirectToAction("Index", "Store");
            }



            return View();

        }


        [HttpPost]
        public ActionResult DeleteAjax(int id)
        {
            //borrarlo
            //Genre g = new Genre() { Description = "Nuevo", Name = "Sarasa" };
            return Json(id);
        }

    }
}
